/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.DynamicGroup;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.message.GetAccountMembershipRequest;
/*     */ import com.zimbra.soap.type.AccountBy;
/*     */ import com.zimbra.soap.type.AccountSelector;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetAccountMembership
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public boolean domainAuthSufficient(Map context)
/*     */   {
/*  55 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean defendsAgainstDelegateAdminAccountHarvesting()
/*     */   {
/*  63 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  69 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  70 */     Provisioning prov = Provisioning.getInstance();
/*  71 */     GetAccountMembershipRequest req = (GetAccountMembershipRequest)JaxbUtil.elementToJaxb(request);
/*  72 */     Key.AccountBy acctBy = req.getAccount().getBy().toKeyAccountBy();
/*  73 */     String accountSelectorKey = req.getAccount().getKey();
/*  74 */     Account account = prov.get(acctBy, accountSelectorKey, zsc.getAuthToken());
/*  75 */     defendAgainstAccountHarvesting(account, acctBy, accountSelectorKey, zsc, Rights.Admin.R_getAccountMembership);
/*     */     
/*  77 */     HashMap<String, String> via = new HashMap();
/*  78 */     List<Group> groups = prov.getGroups(account, false, via);
/*     */     
/*  80 */     Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_MEMBERSHIP_RESPONSE);
/*  81 */     for (Group group : groups) {
/*  82 */       Element eDL = response.addNonUniqueElement("dl");
/*  83 */       eDL.addAttribute("name", group.getName());
/*  84 */       eDL.addAttribute("id", group.getId());
/*  85 */       eDL.addAttribute("dynamic", group.isDynamic());
/*  86 */       String viaDl = (String)via.get(group.getName());
/*  87 */       if (viaDl != null) {
/*  88 */         eDL.addAttribute("via", viaDl);
/*     */       }
/*     */       try
/*     */       {
/*  92 */         if (group.isDynamic()) {
/*  93 */           checkDynamicGroupRight(zsc, (DynamicGroup)group, needGetAttrsRight());
/*     */         } else {
/*  95 */           checkDistributionListRight(zsc, (DistributionList)group, needGetAttrsRight());
/*     */         }
/*     */         
/*  98 */         String isAdminGroup = group.getAttr("zimbraIsAdminGroup");
/*  99 */         if (isAdminGroup != null) {
/* 100 */           eDL.addNonUniqueElement("a").addAttribute("n", "zimbraIsAdminGroup").setText(isAdminGroup);
/*     */         }
/*     */       }
/*     */       catch (ServiceException e) {
/* 104 */         if ("service.PERM_DENIED".equals(e.getCode())) {
/* 105 */           ZimbraLog.acl.warn("no permission to view %s of dl %s", new Object[] { "zimbraIsAdminGroup", group.getName() });
/*     */         }
/*     */       }
/*     */     }
/*     */     
/* 110 */     return response;
/*     */   }
/*     */   
/*     */   private Set<String> needGetAttrsRight() {
/* 114 */     Set<String> attrsNeeded = new HashSet();
/* 115 */     attrsNeeded.add("zimbraIsAdminGroup");
/* 116 */     return attrsNeeded;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 121 */     relatedRights.add(Rights.Admin.R_getAccountMembership);
/* 122 */     notes.add("If the authed admin has get attr right on  distribution list attr zimbraIsAdminGroup, it is returned in the response if set.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetAccountMembership.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */